#include <linux/module.h>
#include <linux/bpf.h>
#include <linux/btf_ids.h>
#include <linux/btf.h>
#include <net/xdp.h>
#include "nveth_test_flow.h"

__diag_push();
__diag_ignore_all("-Wmissing-prototypes", "Global functions as their definitions will be in nveth BTF");

__bpf_kfunc int bpf_nveth_nat_flow(struct xdp_buff *xdp, u32 type)
{
	void *data_end = xdp->data_end;
	void *data = xdp->data;
	int len = data_end - data;
	struct flow_offload_tuple *tuple = 0;

	tuple = nveth_testflow_get_flow(data, len, xdp->rxq->dev->ifindex, 0);

	if (!tuple) {
		printk("out interface id:%d\n", tuple->out.ifidx);
	}

	return 0;
}


__diag_pop()

BTF_SET8_START(bpf_nveth_nat_flow_kfunc_set)
BTF_ID_FLAGS(func, bpf_nveth_nat_flow, KF_TRUSTED_ARGS)
BTF_SET8_END(bpf_nveth_nat_flow_kfunc_set)



static const struct btf_kfunc_id_set bpf_nveth_nat_flow_kfunc_set_id = {
	.owner = THIS_MODULE,
	.set   = &bpf_nveth_nat_flow_kfunc_set,
};

int register_bpf_nveth_kfunc(void)
{
	int ret;

	ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &bpf_nveth_nat_flow_kfunc_set_id);
	if (ret)
		return ret;

	return register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &bpf_nveth_nat_flow_kfunc_set_id);
}


